package ua.dou.utils;

import com.google.code.rome.android.repackaged.com.sun.syndication.feed.atom.Entry;

import android.util.Log;

import java.io.*;

/**
 * Created with IntelliJ IDEA.
 * User: funbox
 * Date: 3/31/13
 * Time: 4:49 AM
 * To change this template use File | Settings | File Templates.
 */
public final class Utils {

    public static byte[] serializeEntry(Entry entry) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        try {
            ObjectOutput out = new ObjectOutputStream(bos);
            out.writeObject(entry);
            out.close();

            // Get the bytes of the serialized object
            byte[] buf = bos.toByteArray();

            return buf;
        } catch(IOException ioe) {
            Log.e("serializeObject", "error", ioe);

            return null;
        }}


    public static Entry deserializeEntry(byte[] b) {
        try {
            ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(b));
            Entry entry = (Entry) in.readObject();
            in.close();

            return entry;
        } catch(ClassNotFoundException cnfe) {
            Log.e("deserializeObject", "class not found error", cnfe);

            return null;
        } catch(IOException ioe) {
            Log.e("deserializeObject", "io error", ioe);

            return null;
        }
    }
}